home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F24447_VPWnd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-10  |  3.2 KB  |  141 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 1999                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10. // VPWnd.cpp : implementation file
  11. // TurboCAD SDK: new class implementation
  12.  
  13. #include "stdafx.h"
  14. #include "MakeDwg.h"
  15. #include "VPWnd.h"
  16.  
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CViewWnd
  25. // TurboCAD SDK: class created to manage view on dialog box
  26.  
  27. CViewWnd::CViewWnd() :
  28.     m_pView(NULL),
  29.     m_pIDrawing(NULL)
  30. {
  31. }
  32.  
  33. CViewWnd::~CViewWnd()
  34. {
  35.     SetView(NULL);
  36. }
  37.  
  38.  
  39. BEGIN_MESSAGE_MAP(CViewWnd, CWnd)
  40.     //{{AFX_MSG_MAP(CViewWnd)
  41.     ON_WM_PAINT()
  42.     ON_WM_ERASEBKGND()
  43.     //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45.  
  46. // TurboCAD SDK: set the view, if one already exists, delete and release it
  47. //               before assigning the new one.
  48. void CViewWnd::SetView(View* pView)
  49. {
  50.     if (m_pView != NULL)
  51.     {
  52.         // Delete view object
  53.         m_pView->Delete();
  54.  
  55.         // Decrement reference count
  56.         m_pView->Release();
  57.         m_pView = NULL;
  58.         if (m_pIDrawing != NULL)
  59.         {
  60.             m_pIDrawing->Release();
  61.             m_pIDrawing = NULL;
  62.         }
  63.     }
  64.  
  65.     if (pView == NULL)
  66.         return;
  67.  
  68.     m_pView = pView;
  69.  
  70.     // Increment reference count
  71.     m_pView->AddRef();
  72.  
  73.     // Map window to view
  74.     m_pView->put_HWND((long)m_hWnd);
  75.  
  76.     // Keep a reference to the drawing
  77.     m_pView->get_Drawing(&m_pIDrawing);
  78.  
  79.     // zoom to drawing extents and invalidate the window
  80.     ZoomAndInvalidate();
  81. }
  82.  
  83. IDrawing* CViewWnd::GetDrawing()
  84. {
  85.     if (m_pIDrawing != NULL)
  86.         m_pIDrawing->AddRef();
  87.     return m_pIDrawing;
  88. }
  89.  
  90. Graphics* CViewWnd::GetGraphics()
  91. {
  92.     Graphics* pGraphics = NULL;
  93.     if (m_pIDrawing != NULL)
  94.         m_pIDrawing->get_Graphics(&pGraphics);
  95.     return pGraphics;
  96. }
  97.  
  98. // TurboCAD SDK: zoom to drawing extents and invalidate the window
  99. void CViewWnd::ZoomAndInvalidate()
  100. {
  101.     // No view, exit
  102.     if (m_pView == NULL)
  103.         return;
  104.  
  105.     // Zoom to extents
  106.     HRESULT hRes = m_pView->ZoomToExtents();
  107.     if (FAILED(hRes))
  108.     {
  109.     }
  110.  
  111.     // Invalidate window to force redraw
  112.     Invalidate();
  113. }
  114.  
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CViewWnd message handlers
  117.  
  118. // TurboCAD SDK: override OnPaint to refresh the view
  119. void CViewWnd::OnPaint() 
  120. {
  121.     CPaintDC dc(this); // device context for painting
  122.     
  123.     if (m_pView == NULL)
  124.         return;
  125.  
  126.     // Force redraw of view window
  127.     HRESULT hRes = m_pView->Refresh();
  128.     if (FAILED(hRes))
  129.     {
  130.     }
  131. }
  132.  
  133. // TurboCAD SDK: override OnEraseBkgnd to reset the drawing area
  134. BOOL CViewWnd::OnEraseBkgnd(CDC* pDC) 
  135. {
  136.     CRect rect;
  137.     GetClientRect(rect);
  138.     pDC->FillSolidRect(rect, ::GetSysColor(COLOR_WINDOW));
  139.     return TRUE;
  140. }
  141.